export default function useTable(fn, searchParams) {
    const params = {
        pageNum: 1,
        pageSize: 10,
    }
    // 获取请求的数据列表
    let list = [];
    // 列表内容条数
    let total = 0;

    const fetch = () => {
        fn({ ...params, ...searchParams }).then((res) => {
            if (res.code === 200) {
                list = res.list;
                total = res.total;
            }
        });
    };
    fetch()
    // 分页器左右
    const pageChangeHandle = () => {
        fetch();
    };
    // 分页器数字
    const pageSizeChangeHandle = () => {
        fetch();
    };
    // 点击搜索或者重置
    const ListFn = () => {
        fetch();
    };

    return {
        list,
        total,
        ...params,
        pageChangeHandle,
        pageSizeChangeHandle,
        ListFn,
      };

}